/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.c0910g.DAO;

import com.myapp.c0910g.entity.UserRole;
import com.myapp.c0910g.entity.UserRoleFacade;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author BachLe
 */
public class UserRoleDAO {
    UserRoleFacade userRoleFacade = lookupUserRoleFacadeBean();

    private UserRoleFacade lookupUserRoleFacadeBean() {
        try {
            Context c = new InitialContext();
            return (UserRoleFacade) c.lookup("java:global/RadioCabsProject/RadioCabsProject-ejb/UserRoleFacade!com.myapp.c0910g.entity.UserRoleFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public UserRole getRoleByName(String name){
        return userRoleFacade.getUserRoleByName(name);
    }

    public UserRole getRoleById(int id){
        return userRoleFacade.find(id);
    }

    public List<UserRole> getAllUserRole(){
        return userRoleFacade.findAll();
    }
}
